#include "StdAfx.h"
#include "dmAddInPrj2AddIn.h"
#include "DrawPolylineOperator.h"
#include "HDiMineView.h"
#include "DialogParam.h"


CDrawPolylineOperator::CDrawPolylineOperator(HDiMineView* view,IDMAddIn *addin):CAddInBaseOperator(view,addin)
{
	m_pPolylineEnt = dmDbPolyline::New();
	m_pTempLayer = HDiMineView::CreateTempLayer(view);
	m_pTempLayer->InsertEntity(m_pPolylineEnt);
}

CDrawPolylineOperator::~CDrawPolylineOperator(void)
{
	m_pPolylineEnt->Delete();
	m_pTempLayer->Delete();
}
int CDrawPolylineOperator::Init()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	m_pPolylineEnt->Clear();
	PromptMessage(IDS_STRING_MESSAGE);
	return 1;
}
int CDrawPolylineOperator::OnLButtonDown(dmEventInfo &hevent)
{
	dmDPoint ptNew = GetMouseWorldPos(hevent);
	m_pPolylineEnt->InsertPoint(ptNew);
	int num = 0;
	dmDPoint *pts = 0;
	m_pPolylineEnt->GetGraphData(pts,num);
	if(num==1)
		m_pPolylineEnt->InsertPoint(ptNew);
	m_pPolylineEnt->Display();
	return DM_OP_OK;
}
int CDrawPolylineOperator::OnNoButtonDownAndMove(dmEventInfo &hevent)
{
	dmDPoint ptNew = GetMouseWorldPos(hevent);
	m_pPolylineEnt->UpdatePoint(ptNew);
	m_pPolylineEnt->Display();
	return DM_OP_OK;
}
int CDrawPolylineOperator::OnRButtonDown(dmEventInfo &hevent)
{
	dmDbLayer *pToLayer = GetNewDataLayer(-1);
	CdmEntityBase *pNewEnt = m_pPolylineEnt->Clone();
	if (pNewEnt == 0)
		return DM_OP_OK;
	if (pToLayer->InsertEntity(pNewEnt) == DM::eOk)
	{
		pNewEnt->Display();
		AddInsertUndoItem(pNewEnt);
	}
	pNewEnt->Delete();
	m_pPolylineEnt->Clear();
	return DM_OP_OK;
}
